package com.zmn.plat.admin.controller.product.tariff.item.city.price;

import java.math.BigDecimal;
import java.util.Objects;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.zmn.common.utils.math.MathUtil;
import com.zmn.plat.admin.controller.PlatBaseController;
import com.zmn.plat.business.interfaces.product.tariff.item.city.price.ProductTariffItemCityPriceBService;
import com.zmn.plat.business.interfaces.service.tariff.citygroup.ServiceTariffCityGroupBService;
import com.zmn.plat.manager.dictionary.MasterDict;
import com.zmn.plat.model.entity.product.tariff.item.city.price.ProductTariffItemCityPrice;
import com.zmn.plat.model.vo.product.tariff.item.city.price.ProductTariffItemCityPriceVo;
import com.zmn.plat.services.interfaces.area.BaseAreaService;
import com.zmn.plat.services.interfaces.product.ServProductService;
import com.zmn.plat.services.interfaces.product.tariff.item.city.price.ProductTariffItemCityPriceService;
import com.zmn.plat.services.interfaces.service.item.ServiceItemService;
import com.zmn.plat.services.interfaces.service.tariff.ServiceTariffService;

/**
 * 城市价格
 *
 * @author linfeng
 *
 * @since 2020-03-03 10:10:14
 */
public class ProductTariffItemCityPriceBaseController extends PlatBaseController {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource
    protected ProductTariffItemCityPriceService productFaultItemCityPriceService;
    @Resource
    protected ProductTariffItemCityPriceBService productFaultItemCityPriceBService;
    @Resource
    protected ServiceTariffService faultTariffService;
    @Resource
    protected ServProductService servProductService;
    @Resource
    protected ServiceItemService faultItemService;
    @Autowired
    protected BaseAreaService baseAreaService;
    @Autowired
    protected ServiceTariffCityGroupBService faultCityGroupBService;

    public String narrow(Object dividend) {
        if (Objects.isNull(dividend)) {
            return "";
        }
        double div = MathUtil.div(Integer.parseInt(dividend.toString()), MasterDict.COEFFICIENT_MAGNIFICATION, 2);
        BigDecimal b = new BigDecimal(div);
        return b.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
    }

    public ProductTariffItemCityPriceVo transEntityToVo(ProductTariffItemCityPrice productFaultItemCityPrice) {
        ProductTariffItemCityPriceVo productFaultItemCityPriceVo = new ProductTariffItemCityPriceVo();
        if (productFaultItemCityPrice == null) {
            productFaultItemCityPrice = new ProductTariffItemCityPrice();
        }
        BeanUtils.copyProperties(productFaultItemCityPrice, productFaultItemCityPriceVo);
        productFaultItemCityPriceVo.setPriceYuan(narrow(productFaultItemCityPriceVo.getPrice()));
        productFaultItemCityPriceVo.setExternalSettlementPriceYuan(narrow(productFaultItemCityPriceVo.getExternalSettlementPrice()));
        productFaultItemCityPriceVo.setInternalSettlementPriceYuan(narrow(productFaultItemCityPriceVo.getInternalSettlementPrice()));
        productFaultItemCityPriceVo.setNegotiableMaxPriceYuan(narrow(productFaultItemCityPriceVo.getNegotiableMaxPrice()));
        productFaultItemCityPriceVo.setNegotiableMinPriceYuan(narrow(productFaultItemCityPriceVo.getNegotiableMinPrice()));

        return productFaultItemCityPriceVo;
    }
}
